<?php 
$id_solicitud = $_GET['id_solicitud'];


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>...::: Valores en oferta comercial :::...</title>
<link href="../../main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table border="0" width="745" height="800">
  <tr>
    <td width="739" align="left" valign="top"><table width="700" border="0">
      <tr>
        <td width="314"><img src="../img/logo_peq.png" width="151" height="34" /></td>
        <td width="369" align="right" valign="top"><table border="0">
          <tr>
            <td width="83" align="right">N&ordm; de solicitud</td>
            <td>:</td>
            <td><?php echo $id_solicitud;?></td>
          </tr>
          <tr>
            <td align="right">Vendedor</td>
            <td>:</td>
            <td><?php echo $row['nombre'];?></td>
          </tr>
        </table>
          <?php echo date('d/m/Y h:i:s');?></td>
      </tr>
    </table>
      <table width="700" border="0" align="center">
        <tr>
          <td align="center"><h2>Ofertas comerciales detalle</h2></td>
        </tr>
      </table>
      <br />
      <br />
      <strong>Datos de Solicitud<br />
      </strong>
      <table border="0">
        <tr>
          <td width="105">Fecha de craci&oacute;n</td>
          <td>:</td>
          <td width="302"><?php echo $fecha[2]."/".$fecha[1]."/".$fecha[0];?></td>
        </tr>
        <tr>
          <td width="105">Fecha de liberaci&oacute;n</td>
          <td>:</td>
          <td width="302"><?php echo $fecha_lib[2]."/".$fecha_lib[1]."/".$fecha_lib[0]." ".$hora[1];?></td>
        </tr>
        <tr>
          <td>Pago solicitado</td>
          <td>:</td>
          <td><?php echo $row['ct_desc'];?></td>
        </tr>
      </table>
      <br />
      <strong>Datos de Cliente<br />
      </strong>
      <table border="0">
        <tr>
          <td width="95">Rut</td>
          <td width="4">:</td>
          <td width="285"><?php echo $row['cm_rut'];?></td>
          <td width="95">&nbsp;</td>
          <td>&nbsp;</td>
          <td width="207">&nbsp;</td>
        </tr>
        <tr>
          <td width="75">Raz&oacute;n social</td>
          <td>:</td>
          <td width="285"><?php echo $row['cm_sort'];?></td>
          <td width="30">&nbsp;</td>
          <td>&nbsp;</td>
          <td width="207">&nbsp;</td>
        </tr>
        <tr>
          <td>Giro</td>
          <td>:</td>
          <td><?php echo $row['cm_giro'];?></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Direcci&oacute;n</td>
          <td>:</td>
          <td><?php echo $row['cm_direccion'];?></td>
          <td>Pa&iacute;s</td>
          <td>:</td>
          <td><?php echo $row['cm_pais'];?>&nbsp;</td>
        </tr>
        <tr>
          <td>Regi&oacute;n</td>
          <td>:</td>
          <td><?php echo $row['cm_region'];?></td>
          <td>Ciudad</td>
          <td>:</td>
          <td><?php echo $row['cm_ciudad'];?></td>
        </tr>
        <tr>
          <td>Comuna</td>
          <td>:</td>
          <td><?php echo $row['cm_comuna'];?></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Contacto Comercial</td>
          <td>:</td>
          <td><?php echo $row['cm_contacto'];?></td>
          <td>Contacto Cobranza</td>
          <td>:</td>
          <td><?php echo $row['cm_contacto_cbr'];?></td>
        </tr>
        <tr>
          <td>Telefono</td>
          <td>:</td>
          <td><?php echo $row['cm_telefono'];?></td>
          <td>Telefono</td>
          <td>:</td>
          <td><?php echo $row['cm_telefono_cbr'];?></td>
        </tr>
        <tr>
          <td>Fax</td>
          <td>:</td>
          <td><?php echo $row['cm_fax'];?></td>
          <td>Fax</td>
          <td>:</td>
          <td><?php echo $row['cm_fax_cbr'];?></td>
        </tr>
        <tr>
          <td>Email</td>
          <td>:</td>
          <td><?php echo $row['cm_email'];?></td>
          <td>Email</td>
          <td>:</td>
          <td><?php echo $row['cm_email_cbr'];?></td>
        </tr>
      </table>
      <strong><br />
        Datos de Despacho<br />
      </strong><strong> </strong>
      <table border="0">
        <tr>
          <td width="95">Direcci&oacute;n</td>
          <td width="4">:</td>
          <td width="285"><?php echo $row['ad_direccion'];?></td>
          <td width="95">Pa&iacute;s</td>
          <td>:</td>
          <td width="207"><?php echo $row['ad_pais'];?></td>
        </tr>
        <tr>
          <td width="95">Regi&oacute;n</td>
          <td>:</td>
          <td width="285"><?php echo $row['ad_region'];?></td>
          <td width="95">Ciudad</td>
          <td>:</td>
          <td width="207"><?php echo $row['ad_ciudad'];?></td>
        </tr>
        <tr>
          <td>Comuna</td>
          <td>:</td>
          <td><?php echo $row['ad_comuna'];?></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
      </table>
      <br />
      <strong>Datos de Producto</strong><br />
      <table border="0">
        <tr>
          <td width="105">Nombre del producto</td>
          <td width="4">:</td>
          <td width="264"><?php echo $row['solic_npcliente'];?></td>
          <td width="87" align="right">Cantidad</td>
          <td>:</td>
          <td width="187"><?php echo number_format($row['solic_cantidad'],0,',','.')." ".$row['solic_um'];?></td>
        </tr>
        <tr>
          <td width="105">Tipo de  producto</td>
          <td width="4">:</td>
          <td width="264"><?php echo caso($row['solic_tipo']);?></td>
          <td width="87" align="right">&nbsp;</td>
          <td>&nbsp;</td>
          <td width="187">&nbsp;</td>
        </tr>
        <tr>
          <td>F. Solicitada Cliente</td>
          <td>:</td>
          <td><?php echo $row['solic_fecha_solic'];?></td>
          <td align="right">Modalidad</td>
          <td>:</td>
          <td><?php echo $row['solic_modalidad']." %";?></td>
        </tr>
        <?php if($row['solic_bolsa'] != ""){?>
        <tr>
          <td>Tipo de bolsa</td>
          <td>:</td>
          <td><?php echo $row['bolsa_desc'];?></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <?php }?>
        <tr>
          <td>Tipo de producto</td>
          <td>:</td>
          <td><?php echo $row['solic_tprod']." - ".$row['tipo_desc'];?></td>
          <td align="right">Material</td>
          <td>:</td>
          <td><?php echo $row['mat_desc']."(".$row['solic_material'].")";?></td>
        </tr>
        <tr>
          <td>Ancho &Oacute;ptico</td>
          <td>:</td>
          <td><?php echo $row['solic_ancho']." mm";?></td>
          <td align="right">Espesor <?php echo $mat1;?></td>
          <td>:</td>
          <td><?php echo $esp1." &micro;m";?></td>
        </tr>
        <tr>
          <td>Largo &Oacute;ptico</td>
          <td>:</td>
          <td><?php echo $row['solic_largo']." mm";?></td>
          <td align="right"><?php if($mat2 != "") echo "Espesor ".$mat2;?></td>
          <td>:</td>
          <td><?php if($esp2 != "" )echo $esp2." &micro;m";?></td>
        </tr>
        <tr>
          <td>Espesor Total</td>
          <td>:</td>
          <td><?php echo $esp_tot." &micro;m";?></td>
          <td align="right"><?php if($mat3 != "") echo "Espesor ".$mat3;?></td>
          <td><?php if($mat3 != "") echo ":";?></td>
          <td><?php if($mat3 != "" )echo $esp3." &micro;m";?></td>
        </tr>
        <tr>
          <td>Impreso</td>
          <td>:</td>
          <td><?php if($row['solic_impreso'])echo "Si"; else echo "No";?></td>
          <td align="right">Pigmentado</td>
          <td>:</td>
          <td><?php if($row['solic_pigmentado'])echo "Si"; else echo "No";?></td>
        </tr>
        <tr>
          <td>Ruta</td>
          <td>:</td>
          <td><?php echo $row['solic_ruta']." - ".$row['fam_desc'];?></td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
        <tr>
          <td>Peso producto</td>
          <td>:</td>
          <td><?php echo number_format($row_re['result_peso_prod'],2,',','.')." grs.";?></td>
          <td align="right">Ancho Producto</td>
          <td>:</td>
          <td><?php echo $row_re['result_ancho_prod']." mm.";?></td>
        </tr>
        <tr>
          <td>Observaciones</td>
          <td>:</td>
          <td colspan="4"><?php echo $row['solic_obs'];?></td>
        </tr>
      </table>
      <br />
      <strong>Datos de Producto</strong><br />
      <hr />
      <?php 
	  	$query     = "SELECT DISTINCT proc_desc, proc_id, procd_solic_id
						FROM variables_proc_cotiza_view
					   WHERE procd_solic_id =  '$id_solicitud'";
		$rslt_proc = mysql_query($query,$cotiza);
		$row_proc  = mysql_fetch_assoc($rslt_proc);
	  
	  do{?>
      <br />
      <strong><?php echo $row_proc['proc_desc'];?></strong>
      <table border="0" cellpadding="0" cellspacing="0" class="borde_total">
        <tr>
          <td width="350" valign="top"><table width="348" border="0">
            <tr>
              <td width="25" align="center"><strong>N&ordm;</strong></td>
              <td width="209" align="left"><strong>Item</strong></td>
              <td width="100" align="left"><strong>Valor</strong></td>
            </tr>
            <?php 	
				$pr    = $row_proc['proc_id'];
				$query = "SELECT * FROM variables_proc_cotiza_view 
		                   WHERE procd_solic_id = '$id_solicitud' AND procd_proc_id = $pr";
				$rslt  = mysql_query($query,$cotiza);
				$row   = mysql_fetch_assoc($rslt);
				
		$i=0; do{$i++;?>
            <tr <?php if($i % 2) echo "bgcolor=\"#F8F8F8\"";?>>
              <td align="right"><?php echo $i.".-";?></td>
              <td align="left"><?php echo $row['campo_desc'];?></td>
              <td align="left"><?php echo $row['procd_valor'];?></td>
            </tr>
            <?php }while ($row   = mysql_fetch_assoc($rslt));?>
          </table></td>
          <td width="353" valign="top" class="borde_izquierdo"><?php 
		  	$query     = "SELECT * FROM mach_det 
			               WHERE mach_solic_id = '$id_solicitud'
					         AND mach_proc_id  = $pr";
			$rslt_maq  = mysql_query($query,$cotiza);
			$row_maq   = mysql_fetch_assoc($rslt_maq);
			$count_maq = mysql_num_rows($rslt_maq);
			
		  if($count_maq > 0)
		  {
		  ?>
            <div align="center" style="background-color:#FF7800;color:#FFF;"><strong>Maquina</strong></div>
            <table width="200" border="0">
              <tr>
                <td><?php echo $row_maq['mach_id'];?></td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
            </table>
            <table width="100%" height="5" cellpadding="0" cellspacing="0" class="borde_abajo">
              <tr>
                <td></td>
              </tr>
            </table>
            <?php }?>
            <?php 	
				$pr    = $row_proc['proc_id'];
				
				if($pr == 2)
					$query = "SELECT pt_desc, receta_pct_pt as insd_cantidad FROM receta_view 
		                       WHERE receta_solic_id = '$id_solicitud'";
				else
					$query = "SELECT * FROM insumos_view 
		                       WHERE insd_solic_id = '$id_solicitud' 
						         AND insd_proc_id = $pr";
								 
				$rslt  = mysql_query($query,$cotiza);
				$row   = mysql_fetch_assoc($rslt);
				$cant  = mysql_num_rows($rslt);
			
			if($cant > 0){
			?>
            <div align="center" style="background-color:#FF7800;color:#FFF;"><strong>Insumos</strong></div>
            <table width="334" border="0">
              <tr>
                <td width="238" align="left"><strong>Descripci&oacute;n</strong></td>
                <td width="59" align="left"><strong>Cantidad</strong></td>
                <td width="23" align="left"><strong>UM</strong></td>
              </tr>
              <?php				
		$i=0; do{$i++;?>
              <tr <?php if($i % 2) echo "bgcolor=\"#F8F8F8\"";?>>
                <td align="left"><?php echo $row['pt_desc'];?></td>
                <td align="right"><?php echo $row['insd_cantidad'];?></td>
                <td align="left"><?php if($pr == 2)echo "%"; else echo $row['insd_um'];?></td>
              </tr>
              <?php }while ($row   = mysql_fetch_assoc($rslt));?>
            </table>
            <?php }
		  	$query     = "SELECT * FROM calc_det 
			               WHERE calc_solic_id = '$id_solicitud' 
						     AND calc_proc_id = $pr
					    ORDER BY calc_posicion_mat ASC";
			$rslt_calc = mysql_query($query,$cotiza);
			$row_calc  = mysql_fetch_assoc($rslt_calc);
			$n_calc    = mysql_num_rows($rslt_calc);
		  ?>
            <div align="center" style="background-color:#FF7800;color:#FFF;"><strong>Entradas y Salida de Material</strong></div>
            <table border="0">
              <tr>
                <td width="80" align="left"><strong>Material</strong></td>
                <td align="left"><strong>Entrada KG</strong></td>
                <td align="left"><strong>Salida KG</strong></td>
                <td align="left"><strong>Entrada MT</strong></td>
                <td align="left"><strong>Salida MT</strong></td>
              </tr>
              <?php				
		$i=0; do{$i++;?>
              <tr <?php if($i % 2) echo "bgcolor=\"#F8F8F8\"";?>>
                <td align="left"><?php echo $row_calc['calc_mat_id'];?></td>
                <td align="right"><?php echo number_format($row_calc['calc_cant_gr_in'],1,',','.');?></td>
                <td align="right"><?php echo number_format($row_calc['calc_cant_gr_out'],1,',','.');?></td>
                <td align="right"><?php echo number_format($row_calc['calc_cant_mt_in'],1,',','.');?></td>
                <td align="right"><?php echo number_format($row_calc['calc_cant_mt_out'],1,',','.');?></td>
              </tr>
              <?php }while ($row_calc  = mysql_fetch_assoc($rslt_calc));?>
            </table>
            <?php //Muestra el material a comprar para el proceso de compras
		  	if($pr == 1)
			{
				$query    = "SELECT * FROM comprados_view WHERE compra_id_solicitud = '$id_solicitud'";
				$rslt_com = mysql_query($query,$cotiza);
				$row_com  = mysql_fetch_assoc($rslt_com);			
		  ?>
            <div align="center" style="background-color:#FF7800;color:#FFF;"><strong>Compra de material</strong></div>
            <table border="0">
              <tr>
                <td width="264" align="left"><strong>Material</strong></td>
                <td width="107" align="left"><strong> KG</strong></td>
                <td width="115" align="left"><strong>Ancho</strong></td>
              </tr>
              <?php				
		$i=0; do{$i++;?>
              <tr <?php if($i % 2) echo "bgcolor=\"#F8F8F8\"";?>>
                <td align="left"><?php echo $row_com['pt_desc'];?></td>
                <td align="right"><?php echo number_format($row_calc['calc_cant_gr_in'],1,',','.');?></td>
                <td align="right"><?php echo number_format($row_calc['calc_cant_gr_out'],1,',','.');?></td>
              </tr>
              <?php }while ($row_com  = mysql_fetch_assoc($rslt_com));?>
            </table>
            <?php }//if($pr == 1)?></td>
        </tr>
      </table>
      <?php }while ($row_proc = mysql_fetch_assoc($rslt_proc))?></td>
  </tr>
</table>
</body>
</html>